package com.literaryfamily.literaryfamily.service.payment.impl;

import com.literaryfamily.literaryfamily.entity.Payments;
import com.literaryfamily.literaryfamily.enumPackage.PaymentMethod;
import com.literaryfamily.literaryfamily.model.ReturnResult;
import com.literaryfamily.literaryfamily.myUtil.SpringContextUtil;

public abstract class Payment {
	/**
	 * 用来交易的接口
	 *
	 * @param paymentAmount   交易金额
	 * @param account         交易账户(为负时向此账户转账,为正时不使用)
	 * @param description     交易描述
	 * @param paymentOrdersId 订单号
	 * @param type 平台类型
	 * @return
	 */
	public abstract ReturnResult<String> placeAnOrder(String paymentAmount, String account, String description, String paymentOrdersId, int type) throws Exception;

	/**
	 * 根据传入的外部或者内部订单号查询并更新对应订单信息
	 * @param paymentId
	 * @return
	 * @throws Exception
	 */
	public abstract ReturnResult<Payments> selectOrderByTransactionId(String paymentId) throws Exception;

	/**
	 * 取消某个订单
	 * @param paymentId 对应的订单号
	 */
	public abstract ReturnResult<Boolean> closeOrderByTransactionId(String paymentId, String msg) throws Exception;

	/**
	 * 获取支付方式
	 * @param type 选择的类型
	 * @return 对应的支付类不存在时返回null
	 */
	public static Payment getPayment(PaymentMethod type) {
		return switch (type) {
			case ALIPAY -> SpringContextUtil.getBean(PaymentTypeAlipayPay.class);
			case WECHAT -> null;
			default -> null;
		};
	}
}